package cn.ecnu.auction.util;
/**
 * @author lychen
 * Date:2012-08-19 
 * comment: 过滤器，保证请求和输出都是utf-8。
 */
import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CodeFilter implements Filter {
	protected FilterConfig filterConfig;
	private String targetEncoding = "UTF-8";
	public void destroy() {
		this.filterConfig = null;
	}

	public void doFilter(ServletRequest srequest, ServletResponse sresponse,
			FilterChain chain) throws IOException, ServletException {
		// TODO Auto-generated method stub
		HttpServletRequest request = (HttpServletRequest)srequest;
		HttpServletResponse response = (HttpServletResponse)sresponse;
		/*String url = request.getRequestURI();
		if(url.indexOf(".jpg")>=0||url.indexOf(".png")>=0||url.indexOf(".jpeg")>=0||url.indexOf(".gif")>=0)
		{			
		}
		else
		{
			System.out.println(url);
		}*/
		
		request.setCharacterEncoding( targetEncoding );		
		response.setContentType("text/html;charset="+targetEncoding);
		
		chain.doFilter( srequest , sresponse );	
	}

	public void init(FilterConfig arg0) throws ServletException {
		
		
	}

}

